package com.huike.web.controller.report;


import com.huike.clues.domain.vo.BusinessChangeStatisticsVO;
import com.huike.clues.domain.vo.ClueChangeStatisticsVO;
import com.huike.common.core.domain.model.LoginUser;
import com.huike.common.utils.SecurityUtils;
import com.huike.report.domain.vo.IndexBaseInfoVO;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;




    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){
        Date todayDate = new Date();
        String date = new SimpleDateFormat("yyyy-MM-dd").format(todayDate);
        String username = SecurityUtils.getUsername();
        IndexTodayInfoVO todayInfo = reportService.getTodayInfo(username, date);
        return AjaxResult.success(todayInfo);
    }

    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        String username = SecurityUtils.getUsername();

        return AjaxResult.success(reportService.getTodoInfo(beginCreateTime,endCreateTime,username));
    }

    @GetMapping("/businessChangeStatistics")
    public AjaxResult getBusinessChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                                  @RequestParam("endCreateTime") String endCreateTime){
        List<BusinessChangeStatisticsVO> businessChangeStatisticsVO = reportService.getBusinessChangeStatistics(beginCreateTime,endCreateTime);


        return AjaxResult.success(businessChangeStatisticsVO);
    }


    @GetMapping("/salesStatistic")
    public AjaxResult getSalesStatistic(@RequestParam("beginCreateTime") String beginCreateTime,
                                        @RequestParam("endCreateTime") String endCreateTime){
        List<ClueChangeStatisticsVO> clueChangeStatisticsVOS = reportService.getSalesStatistic(beginCreateTime,endCreateTime);

        return AjaxResult.success(clueChangeStatisticsVOS);
    }


}